package com.lenovo.manufacture.module;

import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beardedhen.androidbootstrap.BootstrapLabel;
import com.lenovo.manufacture.BaseActivity;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.adapter.MyAdapter;
import com.lenovo.manufacture.annotation.Layout;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

public class Module3 extends BaseActivity {

    @BindView(R.id.tv_type)
    BootstrapLabel tvType;
    @BindView(R.id.tv_price)
    BootstrapLabel tvPrice;
    @BindView(R.id.rv_person)
    RecyclerView rvPerson;
    private List<Map<String, String>> people;

    @Layout(value = R.layout.activity_module3, title = "人才市场列表")
    protected void init() {
        async(apiService.getAllPerson(), data -> {
            people = data.getData();
            initList();
        });
    }

    private void initList() {
        List<String> data1 = new ArrayList<>();
        people.forEach(person -> {
            String name = getName(person.get("type"));
            data1.add(person.get("personName"));
            data1.add(name);
            data1.add(decimalFormat.format(Integer.valueOf(person.get("price"))));
        });

        rvPerson.setLayoutManager(new GridLayoutManager(rvPerson.getContext(), 3));
        rvPerson.setAdapter(new MyAdapter(data1));
    }

    private String getName(String type) {
        switch (type) {
            case "0":
                return "工程师";
            case "1":
                return "工人";
            case "2":
                return "技术人员";
            case "3":
                return "质检员";
        }
        return "";
    }

    @OnClick({R.id.tv_type, R.id.tv_price})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_type:
                sort(people, "type", tvType, "类型");
                break;
            case R.id.tv_price:
                sort(people, "price", tvPrice, "薪资");
                break;
        }
        initList();
    }
}
